package com.wy.allthingdone.views;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.graphics.Paint;

import com.wy.allthingdone.R;


/**
 * Created by 38270 on 2016/11/22.
 */

public class TextReaderView extends View {
    private Paint mPaint;


    private String text;

    public TextReaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public TextReaderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public TextReaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.readerText_sty);
        if (array.getText(R.styleable.readerText_sty_readerText) != null) {
            this.text = String.valueOf(array.getText(R.styleable.readerText_sty_readerText));
        } else {
            this.text = "";
        }
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setTextSize(30);
        mPaint.setColor(0xff000000);
        array.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawText(text, getPaddingLeft(), getPaddingTop() + 30, mPaint);
        super.onDraw(canvas);
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
        invalidate();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
